package com.lening.service.impl;

import com.lening.dao.UserDao;
import com.lening.entity.UserBean;
import com.lening.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

/**
 * 创作时间：2020/3/19 14:08
 * 作者：李增强
 */
@Service
public class UserviceImpl implements UserService {
    @Resource
    private UserDao userDao;

    /**
     * jpa的实体管理器，其实底层是hibernate的管理器，后续这个的操作和hibernate的类似
     * 和我们hibernate的session很相似，创建query，query来操作
     */
    @Resource
    private EntityManager entityManager;

    @Override
    public List<UserBean> findAll() {
        Query query = entityManager.createNativeQuery("select * from t_user", UserBean.class);
        List list = query.getResultList();
        System.out.println(list);
        return userDao.findAll();
    }
}
